package com.cherrish.demo;

/**
 * @author cherrish
 * @time 2019-01-11 14:53
 * @name TestString
 * @desc:
 */
public class TestString {
    public static void main(String[] args) {
//        test();
        test1();
    }

    private static void test1(){
        int len = 200000;
        String str = "";
        long t1 = System.currentTimeMillis();
        for(int i = 0; i < len; i++){
            str = str + i;
        }
        long t2 = System.currentTimeMillis();
//        System.out.println(str);
        System.out.println(t2 - t1);

        StringBuilder stringBuilder = new StringBuilder("");
        t1 = System.currentTimeMillis();
        for(int i = 0; i < len; i++){
            stringBuilder.append(i);
        }
        str = stringBuilder.toString();
        t2 = System.currentTimeMillis();
//        System.out.println(str);
        System.out.println(t2 - t1);


        StringBuffer stringBuffer = new StringBuffer("");
        t1 = System.currentTimeMillis();
        for(int i = 0; i < len; i++){
            stringBuffer.append(i);
        }
        str = stringBuffer.toString();
        t2 = System.currentTimeMillis();
//        System.out.println(str);
        System.out.println(t2 - t1);
    }

    public static final String test1 = "test";
    public static final String test2 = "test";

    public static void test() {

        String test3 = "test";
        String test = "test";

        System.out.println(test3.equals(test));
        System.out.println(test3 == test);
        System.out.println(test1.equals(test2));
        System.out.println(test1 == test2);
        System.out.println(test1 == test3);
        System.out.println(test1 == new String("test"));
    }
}
